package com.shop.vuedemo.config;

import com.shop.vuedemo.filter.MyFilter;
import com.shop.vuedemo.filter.MyFilter2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * projectName: vueDemo
 * create on 2021/11/21 21:10
 *
 * @author yanbl
 * @Description :
 */
@Configuration
public class FilterConfig {

    @Autowired
    private MyFilter myFilter;

    @Autowired
    private MyFilter2 myFilter2;

    @Bean
    public FilterRegistrationBean registrationFilter() {
        FilterRegistrationBean<Filter> registrationFilter = new FilterRegistrationBean<>();
        registrationFilter.setFilter(myFilter);
        registrationFilter.setOrder(1);
        registrationFilter.setName("myFilter");
        registrationFilter.addUrlPatterns("/login/*");
        return registrationFilter;
    }

    @Bean
    public FilterRegistrationBean registrationFilter2() {
        FilterRegistrationBean<Filter> registrationFilter = new FilterRegistrationBean<>();
        registrationFilter.setFilter(myFilter2);
        registrationFilter.setOrder(2);
        registrationFilter.setName("myFilter2");
        registrationFilter.addUrlPatterns("/test/shop/*");
        return registrationFilter;
    }
}
